﻿using System;
using System.Text;
using Yaml.Utilities;

namespace Yaml.Presentation.Tokens {
    public class StreamStartToken : Token {
        Encoding encoding;

        public StreamStartToken(Mark start, Mark end, Encoding encoding) : base(start, end) {
            this.encoding = encoding;
        }

        public Encoding Encoding {
            get { return this.encoding; }
        }

        public string EncodingName {
            get {
                if (this.encoding.Equals(Encoding.UTF8)) {
                    return "utf-8";
                }
                if (this.encoding.Equals(Encoding.Unicode)) {
                    return "utf-16-le";
                }
                if (this.encoding.Equals(Encoding.BigEndianUnicode)) {
                    return "utf-16-be";
                }
                return encoding.EncodingName;
            }
        }

        public override string ToString() {
            return "#<" + this.GetType().Name + " encoding='" + EncodingName + "' start=" + Start.ToString() + " end=" + End.ToString() + ">";
        }
    }
}
